package otherPractice;

public class Bank {
	
	//volatile
	private volatile int amount = 0;
	
	
	//存钱       synchronized
	public synchronized void addMoney(int money) {
		amount = amount + money;
		System.out.println(System.currentTimeMillis() + "s  存进--" + money + "--元" + "s  余额=" + amount);
	}
	
	//取钱
	public  synchronized void subMoney(int money) {
		if(amount - money >= 0) {
			amount = amount - money;
			System.out.println(System.currentTimeMillis() + "s  取出--" + money+ "--元" + "s  余额=" + amount);
		}else {
			System.out.println(System.currentTimeMillis() +"s  取出--余额不足");
		}
	}
	
	//查询余额
	public void lookMoney() {
		System.out.println(System.currentTimeMillis() + "s  余额=" + amount);
	}
	
	
}
